11 typedef pair
<node
, node
> edge
;
12 typedef map
<node
, vector
<node
> > graph
;
14 bool dfs(node v
, node destiny
, set
<node
> visited
, const graph
&g
, const set
<node
> &forbidden
){
15 vector
<node
> neighbors
= (*(g
.find(v
))).second
;
16 for (int i
=0; i
<neighbors
.size(); ++i
){
17 if (neighbors
[i
] == destiny
) return true;
18 if (!(visited
.count(neighbors
[i
])) && !(forbidden
.count(neighbors
[i
]))){
19 set
<node
> temp
= visited
;
21 if (dfs(neighbors
[i
], destiny
, temp
, g
, forbidden
)){
29 bool validate(edge e
, const graph
&g
, const set
<node
> &forbidden
){
31 return (dfs(e
.first
, e
.second
, visited
, g
, forbidden
));
36 while (getline(cin
, name1
) && name1
!= "END"){
41 while (getline(cin
, line
) && line
!= "* * *"){
45 sin
>> e
.first
>> e
.second
;
47 forbidden
.insert(e
.first
);
48 forbidden
.insert(e
.second
);
52 while (getline(cin
, line
) && line
!= "* * *"){
56 sin
>> e
.first
>> e
.second
;
58 if (g
.count(e
.first
) == 0){
61 if (g
.count(e
.second
) == 0){
64 g
[e
.first
].push_back(e
.second
);
65 g
[e
.second
].push_back(e
.first
);
69 for (set
<node
>::iterator it
= forbidden
.begin(); it
!= forbidden
.end(); ++it
){
70 if (g
.count((*it
)) == 0){
71 cout
<< "NO: " << name2
<<" is not a more detailed version of " << name1
<< endl
;
75 bool impossible
= false;
76 for (int i
=0; i
<streets
.size(); ++i
){
77 if (!validate(streets
[i
], g
, forbidden
)){
83 cout
<< "NO: " << name2
<<" is not a more detailed version of " << name1
<< endl
;
85 cout
<< "YES: " << name2
<<" is a more detailed version of " << name1
<< endl
;